<template>
  <div class="workbench-page">
    <!-- 头部区域 -->
    <div class="header-section">
      <h1 class="page-title">工作台</h1>
      <div class="header-stats">
        <div class="stat-item">
          <span class="stat-value">{{ taskCount || 0 }}</span>
          <span class="stat-label">待办任务</span>
        </div>
        <div class="stat-item">
          <span class="stat-value">{{ teamCount || 0 }}</span>
          <span class="stat-label">我的团队</span>
        </div>
        <div class="stat-item">
          <span class="stat-value">{{ notificationCount || 0 }}</span>
          <span class="stat-label">新通知</span>
        </div>
      </div>
    </div>

    <!-- 快捷操作区域 -->
    <div class="quick-actions">
      <div class="action-grid">
        <div class="action-item" @click="navigateTo('/chatCenter')">
          <div class="action-icon bg-blue">
            <img src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath fill='%23fff' d='M896 192h-64v-64c0-17.664-14.336-32-32-32h-576c-17.664 0-32 14.336-32 32v64h-64c-17.664 0-32 14.336-32 32v576c0 17.664 14.336 32 32 32h64v64c0 17.664 14.336 32 32 32h576c17.664 0 32-14.336 32-32v-64h64c17.664 0 32-14.336 32-32v-576c0-17.664-14.336-32-32-32zM256 288h512v384h-512v-384z'/%3E%3C/svg%3E" alt="" class="icon-img">
          </div>
          <span class="action-name">消息中心</span>
        </div>
        <div class="action-item" @click="navigateTo('/team')">
          <div class="action-icon bg-green">
            <img src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath fill='%23fff' d='M352 224v-64h-64v64h-128v64h128v128h64v-128h128v-64h-128zM960 512v-64h-128v64h-128v128h128v128h64v-128h128v-64h-128zM832 512v-64h-64v64h-128v64h128v128h64v-128h128v-64h-128zM352 960v-64h-64v64h-128v-64h128v-128h64v128h128v64h-128zM576 224v-64h-64v64h-64v64h64v128h64v-128h64v-64h-64zM704 768v-64h-64v64h-64v64h64v64h64v-64h64v-64h-64zM576 512v-64h-64v64h-64v64h64v128h64v-128h64v-64h-64zM352 768v-64h-64v64h-64v64h64v64h64v-64h64v-64h-64zM576 768v-64h-64v64h-64v64h64v64h64v-64h64v-64h-64zM704 224v-64h-64v64h-64v64h64v128h64v-128h64v-64h-64zM352 512v-64h-64v64h-64v64h64v128h64v-128h64v-64h-64zM704 512v-64h-64v64h-64v64h64v128h64v-128h64v-64h-64zM576 960v-64h-64v64h-64v-64h64v-128h64v128h64v64h-64z'/%3E%3C/svg%3E" alt="" class="icon-img">
          </div>
          <span class="action-name">团队管理</span>
        </div>
        <div class="action-item" @click="navigateTo('/applyCenter')">
          <div class="action-icon bg-orange">
            <img src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath fill='%23fff' d='M896 256h-768v448h768v-448zM960 192h-896c-35.344 0-64 28.656-64 64v512c0 35.344 28.656 64 64 64h896c35.344 0 64-28.656 64-64v-512c0-35.344-28.656-64-64-64zM640 384h192v64h-192v-64zM640 512h192v64h-192v-64zM640 640h192v64h-192v-64zM384 384h192v64h-192v-64zM384 512h192v64h-192v-64zM384 640h192v64h-192v-64zM128 384h192v64h-192v-64zM128 512h192v64h-192v-64zM128 640h192v64h-192v-64z'/%3E%3C/svg%3E" alt="" class="icon-img">
          </div>
          <span class="action-name">申请中心</span>
        </div>
        <div class="action-item" @click="navigateTo('/aiChat')">
          <div class="action-icon bg-purple">
            <img src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath fill='%23fff' d='M512 0c-282.752 0-512 229.248-512 512s229.248 512 512 512 512-229.248 512-512-229.248-512-512-512zM512 960c-247.424 0-448-200.576-448-448s200.576-448 448-448 448 200.576 448 448-200.576 448-448 448zM576 384c17.664 0 32-14.336 32-32s-14.336-32-32-32-32 14.336-32 32 14.336 32 32 32zM448 384c17.664 0 32-14.336 32-32s-14.336-32-448-448 448 200.576 448 448-200.576 448-448 448zM576 640c17.664 0 32-14.336 32-32s-14.336-32-32-32-32 14.336-32 32 14.336 32 32 32zM448 640c17.664 0 32-14.336 32-32s-14.336-32-32-32-32 14.336-32 32 14.336 32 32 32zM320 640c17.664 0 32-14.336 32-32s-14.336-32-32-32-32 14.336-32 32 14.336 32 32 32zM704 384c17.664 0 32-14.336 32-32s-14.336-32-32-32-32 14.336-32 32 14.336 32 32 32z'/%3E%3C/svg%3E" alt="" class="icon-img">
          </div>
          <span class="action-name">AI助手</span>
        </div>
      </div>
    </div>

    <!-- 近期动态区域 -->
    <div class="recent-activities">
      <div class="section-header">
        <h2>近期动态</h2>
        <span class="view-more" @click="navigateTo('/activities')">查看更多</span>
      </div>
      <div class="activity-list">
        <div class="activity-item" v-for="activity in recentActivities" :key="activity.id">
          <div class="activity-icon">
            <img :src="activity.icon" alt="" class="icon-img">
          </div>
          <div class="activity-content">
            <p class="activity-text">{{ activity.text }}</p>
            <span class="activity-time">{{ activity.time }}</span>
          </div>
        </div>
        <div v-if="recentActivities.length === 0" class="empty-activity">
          <p>暂无近期动态</p>
        </div>
      </div>
    </div>

    <!-- 进行中的项目 -->
    <div class="ongoing-projects">
      <div class="section-header">
        <h2>进行中的项目</h2>
        <span class="view-more" @click="navigateTo('/projects')">查看更多</span>
      </div>
      <div class="project-list">
        <div class="project-item" v-for="project in ongoingProjects" :key="project.id">
          <div class="project-header">
            <h3 class="project-name">{{ project.name }}</h3>
            <span class="project-status" :class="`status-${project.status}`">{{ project.statusText }}</span>
          </div>
          <div class="project-progress">
            <div class="progress-bar">
              <div class="progress-fill" :style="{ width: project.progress + '%' }"></div>
            </div>
            <span class="progress-text">{{ project.progress }}%</span>
          </div>
          <div class="project-info">
            <span class="project-meta">{{ project.teamName }}</span>
            <span class="project-meta">{{ project.deadline }}</span>
          </div>
        </div>
        <div v-if="ongoingProjects.length === 0" class="empty-project">
          <p>暂无进行中的项目</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { userStore } from '../stores/user/user.ts';

export default {
  name: 'WorkbenchPage',
  setup() {
    const router = useRouter();
    const userStoreAPI = userStore();
    
    // 统计数据
    const taskCount = ref(3);
    const teamCount = ref(5);
    const notificationCount = ref(2);
    
    // 近期动态
    const recentActivities = ref([
      {
        id: 1,
        icon: 'data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"%3E%3Cpath fill="%234caf50" d="M512 0c-282.752 0-512 229.248-512 512s229.248 512 512 512 512-229.248 512-512-229.248-512-512-512zM512 960c-247.424 0-448-200.576-448-448s200.576-448 448-448 448 200.576 448 448-200.576 448-448 448zM416 448h192v96h-192v-96zM416 576h192v96h-192v-96z"/%3E%3C/svg%3E',
        text: '张三邀请你加入"智能伙伴"团队',
        time: '10分钟前'
      },
      {
        id: 2,
        icon: 'data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"%3E%3Cpath fill="%232196f3" d="M896 192h-64v-64c0-17.664-14.336-32-32-32h-576c-17.664 0-32 14.336-32 32v64h-64c-17.664 0-32 14.336-32 32v576c0 17.664 14.336 32 32 32h64v64c0 17.664 14.336 32 32 32h576c17.664 0 32-14.336 32-32v-64h64c17.664 0 32-14.336 32-32v-576c0-17.664-14.336-32-32-32zM256 288h512v384h-512v-384z"/%3E%3C/svg%3E',
        text: '李四给你发送了一条新消息',
        time: '1小时前'
      },
      {
        id: 3,
        icon: 'data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"%3E%3Cpath fill="%23ff9800" d="M896 256h-768v448h768v-448zM960 192h-896c-35.344 0-64 28.656-64 64v512c0 35.344 28.656 64 64 64h896c35.344 0 64-28.656 64-64v-512c0-35.344-28.656-64-64-64zM640 384h192v64h-192v-64zM640 512h192v64h-192v-64zM640 640h192v64h-192v-64zM384 384h192v64h-192v-64zM384 512h192v64h-192v-64zM384 640h192v64h-192v-64zM128 384h192v64h-192v-64zM128 512h192v64h-192v-64zM128 640h192v64h-192v-64z"/%3E%3C/svg%3E',
        text: '项目"智能匹配系统"已更新进度',
        time: '3小时前'
      }
    ]);
    
    // 进行中的项目
    const ongoingProjects = ref([
      {
        id: 1,
        name: '智能匹配系统',
        progress: 75,
        status: 'normal',
        statusText: '进行中',
        teamName: '研发一组',
        deadline: '2023-12-31'
      },
      {
        id: 2,
        name: '用户体验优化',
        progress: 45,
        status: 'normal',
        statusText: '进行中',
        teamName: '设计团队',
        deadline: '2023-12-15'
      },
      {
        id: 3,
        name: '数据统计分析',
        progress: 90,
        status: 'warning',
        statusText: '即将完成',
        teamName: '数据组',
        deadline: '2023-12-10'
      }
    ]);

    // 初始化数据
    onMounted(() => {
      // 在实际项目中，这里可以从后端获取真实数据
      // 模拟数据已经在上面定义
    });

    // 导航到指定页面
    const navigateTo = (path) => {
      router.push(path);
    };

    return {
      taskCount,
      teamCount,
      notificationCount,
      recentActivities,
      ongoingProjects,
      navigateTo
    };
  }
};
</script>

<style scoped>
.workbench-page {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* 头部区域 */
.header-section {
  background: linear-gradient(135deg, #3e7bfa 0%, #1a5fd0 100%);
  color: white;
  padding: 20px 16px;
  position: relative;
}

.page-title {
  font-size: 24px;
  font-weight: bold;
  margin: 0 0 20px 0;
}

.header-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  opacity: 0.9;
}

/* 快捷操作区域 */
.quick-actions {
  background-color: white;
  margin-top: -20px;
  border-radius: 16px 16px 0 0;
  padding: 24px 16px 16px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.action-item:active {
  transform: scale(0.95);
}

.action-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.action-icon.bg-blue {
  background-color: #3e7bfa;
}

.action-icon.bg-green {
  background-color: #4caf50;
}

.action-icon.bg-orange {
  background-color: #ff9800;
}

.action-icon.bg-purple {
  background-color: #9c27b0;
}

.icon-img {
  width: 28px;
  height: 28px;
}

.action-name {
  font-size: 13px;
  color: #333;
}

/* 通用区域样式 */
.recent-activities,
.ongoing-projects {
  background-color: white;
  margin-top: 12px;
  padding: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #333;
}

.view-more {
  font-size: 14px;
  color: #3e7bfa;
  cursor: pointer;
}

/* 近期动态列表 */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.activity-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background-color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
}

.activity-text {
  font-size: 14px;
  color: #333;
  margin: 0 0 4px 0;
  line-height: 1.4;
}

.activity-time {
  font-size: 12px;
  color: #999;
}

/* 项目列表 */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.project-item {
  background-color: #f9f9f9;
  border-radius: 8px;
  padding: 12px;
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.project-name {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
  color: #333;
}

.project-status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
}

.project-status.status-normal {
  background-color: #e3f2fd;
  color: #1976d2;
}

.project-status.status-warning {
  background-color: #fff3e0;
  color: #f57c00;
}

.project-status.status-danger {
  background-color: #ffebee;
  color: #d32f2f;
}

.project-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background-color: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3e7bfa, #1a5fd0);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 12px;
  color: #666;
  min-width: 35px;
  text-align: right;
}

.project-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
}

/* 空状态 */
.empty-activity,
.empty-project {
  padding: 32px 0;
  text-align: center;
  color: #999;
  font-size: 14px;
}

/* 响应式调整 */
@media (max-width: 375px) {
  .header-stats {
    gap: 10px;
  }
  
  .stat-value {
    font-size: 18px;
  }
  
  .action-grid {
    gap: 12px;
  }
  
  .action-icon {
    width: 50px;
    height: 50px;
  }
  
  .icon-img {
    width: 24px;
    height: 24px;
  }
}
</style>